/*
 * Copyright (c) ShaoxiongDu <Shaoxiong.dev@aliyun.com> 2021 all Rights Reserved
 */

package zh.codegym.task.task08.task0824;

/* 
构建家庭
*/

import java.util.ArrayList;

public class Solution {
    public static void main(String[] args) {
        //在此编写你的代码
        Human h1 = new Human("孩子1", 18, true, new ArrayList<>());
        Human h2 = new Human("孩子2", 18, false, new ArrayList<>());
        Human h3 = new Human("孩子3", 18, true, new ArrayList<>());
        Human f1 = new Human("父亲", 18, true, new ArrayList<Human>() {{
            add(h1);
            add(h2);
            add(h3);
        }});
        Human m1 = new Human("母亲", 18, false, new ArrayList<Human>() {{
            add(h1);
            add(h2);
            add(h3);
        }});
        Human f2 = new Human("祖父1", 18, true, new ArrayList<Human>() {{
            add(f1);
        }});
        Human m2 = new Human("祖母1", 18, false, new ArrayList<Human>() {{
            add(f1);
        }});
        Human f3 = new Human("祖父2", 18, true, new ArrayList<Human>() {{
            add(m1);
        }});
        Human m3 = new Human("祖母2", 18, false, new ArrayList<Human>() {{
            add(m1);
        }});
        System.out.println(f3);
        System.out.println(m3);
        System.out.println(f2);
        System.out.println(m2);
        System.out.println(f1);
        System.out.println(m1);
        System.out.println(h1);
        System.out.println(h2);
        System.out.println(h3);
    }

    public static class Human {
        //在此编写你的代码
        String name;
        int age;
        boolean sex;
        ArrayList<Human> children;

        public Human(String name, int age, boolean sex, ArrayList<Human> children) {
            this.name = name;
            this.age = age;
            this.sex = sex;
            this.children = children;
        }

        public String toString() {
            String text = "";
            text += "名字：" + this.name;
            text += "，性别：" + (this.sex ? "男" : "女");
            text += "，年龄：" + this.age;

            int childCount = this.children.size();
            if (childCount > 0) {
                text += "，孩子：" + this.children.get(0).name;

                for (int i = 1; i < childCount; i++) {
                    Human child = this.children.get(i);
                    text += "，" + child.name;
                }
            }
            return text;
        }
    }

}
